#ifndef _MATCHING_H_
#define _MATCHING_H_

#include "Opencv.h"
//#include "KLTFlow.h"
#include "FBFlow.h"
#include "compareFeatures.h"
static const int ColorGroupNum = 16;
static const CvScalar colorlist[ColorGroupNum] =
  {CV_RGB(0,  0,  255), CV_RGB(  0, 94,255), CV_RGB(  0,191,255), CV_RGB(  0,255,255),
   CV_RGB(  0,255,128), CV_RGB(  0,255, 34), CV_RGB( 64,255,  0), CV_RGB(157,255,  0),
   CV_RGB(255,255,  0), CV_RGB(255,162,  0), CV_RGB(255, 64,  0), CV_RGB(255,  0, 30),
   CV_RGB(255,  0,128), CV_RGB(255,  0,221), CV_RGB(192,  0,255), CV_RGB( 98,  0,255)};
static CvRNG rng_state = cvRNG(-1);
typedef pair<float,float> P2d;



void convertflowPoint2P2d(vector<Point2f> flowpoint, vector<Point2f> flowscale, vector< pair<P2d,P2d> > *vals);

void convertP2d2flowPoint(vector< pair<P2d,P2d> > vals, vector<Point2f> *flowpoint, vector<Point2f> *flowscale);


int simpleRansac(const vector< pair<P2d,P2d> > vals,float result[2][2]);

void selectPoints(const vector< pair<P2d,P2d> > vals, float param[2][2],
		  vector< pair<P2d,P2d> > *selected);

int fileFlowData(int imcount,
                      const vector< pair<P2d,P2d> > vals,
                      const vector< pair<P2d,P2d> > selected);

int countPic(const cv::Mat input);

void calcImageCenter(const cv::Mat input, Point2f *center);

float calcMode(list<float> point, int num);

void calcFlowMode(vector<Point2f> input, vector<Point2f> *output, int num);

float calcMean(list<float> point);

void calcMeanVar(vector< pair<P2d,P2d> > features, pair<P2d,P2d> *mean, pair<P2d,P2d> *var);

cv::Mat makeMask(cv::Mat input);

cv::Mat loadImage(std::string dirname, int imagenum);

cv::Mat boxedMask(cv::Mat input, int step);

void boxedFlow(std::vector<Point2f> flowPoint, std::vector<Point2f> flowScale, std::vector<Point2f> *boxedflowPoint, std::vector<Point2f> *boxedflowScale, int step, cv::Mat input);

void extractRangeFlow(vector<Point2f> flowPoint, vector<Point2f> flowscale, vector<Point2f> *resultFlowPoint, vector<Point2f> *resultFlowScale, float  maxshre, float  minshre);

int saveFlowData(std::vector<Point2f> flowPoint, std::vector<Point2f> flowScale, int imnum);

void firstProc(std::string dirname, int imcount, cv::Mat& output);

void display(int cnum, cv::Mat input, cv::Mat &output, vector< pair<P2d,P2d> > flow, char* windowname);

void calcMaxScale(std::vector<Point2f> flowScale, float &maxScale);

cv::Mat genFlowHist(std::vector<Point2f> flowScale, std::vector<Point2f> flowPoint, cv::Mat input);

void calcDnsArea(std::vector<Point2f> flowPoint, std::vector<Point2f> flowScale, int step, cv::Mat input, float thre, cv::Mat &maskImage);

void resizeSrcImg(cv::Mat input, cv::Mat &output, float scale, int interpolation);

//void Proc(KLT klt, char *dirname, int imcount, cv::Mat& output,vector<Point2f> &flowPoint,vector<Point2f> &flowScale);


#endif
